package com.block.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.block.common.service.IAddressInfoService;
import com.block.db.entity.AddressInfo;
import com.block.db.mapper.AddressInfoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2022-12-05
 */
@Service
public class AddressInfoServiceImpl extends ServiceImpl<AddressInfoMapper, AddressInfo> implements IAddressInfoService {


    @Override
    public AddressInfo getAddressInfoByCode(String codeValue){
        // TODO: 2024/8/20 添加缓存
        return this.getById(codeValue);
    }

    @Override
    public AddressInfo getAddressInfoByParentNameAndName(String parentName, String name) {
        LambdaQueryWrapper<AddressInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AddressInfo::getParentName, parentName);
        queryWrapper.likeRight(AddressInfo::getName, name);
        queryWrapper.eq(AddressInfo::getType, "2");
        queryWrapper.last("limit 1");
        return baseMapper.selectOne(queryWrapper);
    }

}
